// 版权归 瞄你个汪 所有。使用本代码应遵守相关法律法规和Apache 2.0开源许可要求。
package top.geeke.database;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.geeke.handler.TableTenantLineHandler;

/**
 * <p>
 * MybatisPlus 配置
 * </p>
 * @author 瞄你个汪
 * @since 2024/6/2 16:30
 */
@Configuration
@MapperScan("top.geeke.mapper")
public class MybatisPlusConfig {
    @Autowired
    private TableTenantLineHandler tableTenantLineHandler;

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        TenantLineInnerInterceptor tenantInterceptor = new TenantLineInnerInterceptor();
        tenantInterceptor.setTenantLineHandler(tableTenantLineHandler);
        interceptor.addInnerInterceptor(tenantInterceptor);

        // 在对应mapper方法上添加注解可忽略租户 @InterceptorIgnore(tenantLine = "true")

        // 分页配置
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
